package com.gongJiao.service.impl;

import com.gongJiao.Vo.PageCondition;
import com.gongJiao.Vo.RouteVo;
import com.gongJiao.entity.Route;
import com.gongJiao.entity.Vehicle;
import com.gongJiao.mapper.RouteMapper;
import com.gongJiao.mapper.RouteSiteMapper;
import com.gongJiao.service.RouteService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 * @author ${author}
 * @since 2021-12-25
 */
@Service
public class RouteServiceImpl extends ServiceImpl<RouteMapper, Route> implements RouteService {
    @Autowired
    RouteMapper routeMapper;
    @Autowired
    RouteSiteMapper routeSiteMapper;
    /**
     * 获取路线信息集合
     * @return
     */
    @Override
    public List<Route> getRouteList() {
        return routeMapper.selectList(null);
    }

    /**
     * 根据路线名称分页查询路线信息集合
     * @param pageCondition
     * @return
     */
    @Override
    public List<RouteVo> getRouteListByName(PageCondition pageCondition) {
        return routeMapper.getRouteListByName(pageCondition);
    }

    /**
     * 根据路线名称分页查询路线数量
     * @param pageCondition
     * @return
     */
    @Override
    public Integer getCountByName(PageCondition pageCondition) {
        return routeMapper.getCountByName(pageCondition);
    }
    /**
     * 判断路线名是否可用
     * @param name
     * @return
     */
    @Override
    public Route getVehicleByName(String name) {
        if (name == null && "".equals(name)) {
            return null;
        }
        return routeMapper.getvehicleByName(name);
    }

    /**
     * 添加路线并返回id
     * @param route
     * @return
     */
    @Override
    public Long addRoute(Route route) {
        int insert = routeMapper.insert(route);
        return route.getId();
    }
    /**
     * 根据id获取路线信息
     * @param id
     * @return
     */
    @Override
    public Route getRouteById(Long id) {
        return routeMapper.selectById(id);
    }
    /**
     * 跟据id修改路线
     * @param route
     * @return
     */
    @Override
    public int updateRouteById(Route route) {
        return routeMapper.updateById(route);
    }

    /**
     * 根据路线id删除信息
     * @param ids
     */
    @Override
    public void deleteRouteByIds(Long ids) {
        //删除路线表
        routeMapper.deleteById(ids);
        //删除相关表
        routeSiteMapper.deleteByRouteId(ids);
    }

    /**
     * 跟据就站点id查找使用站点的路线名称集合字符串
     * @param ids
     * @return
     */
    @Override
    public String getRoutBySiteId(Long ids) {
        return routeMapper.getRoutBySiteId(ids);
    }
}
